"""
property动态属性
"""

from datetime import datetime, date


class User:
    def __init__(self, name, birthday):
        self.name = name
        self.birthday = birthday
        self.__level = 0

    @property
    def age(self):
        return datetime.now().year - self.birthday.year

    @property
    def level(self):
        return self.__level

    @level.setter
    def level(self, value):
        self.__level = value

    def get_age(self):
        return datetime.now().year - self.birthday.year


def use_user():
    user = User("Kevin", date(year=2008, month=1, day=1))
    print(user.get_age())
    # 使用动态属性
    print(user.age)
    # 输出结果：
    """
    10
    10
    """

    # 使用动态属性
    user.level = 1
    print(user.level)
    # 输出结果：
    """
    1
    """


if __name__ == '__main__':
    use_user()
